package com.yiyi.credit.manage.sso.mapper;

import com.yiyi.credit.manage.sso.common.mapper.CommonMapper;
import com.yiyi.credit.manage.sso.model.entity.SysResource;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


public interface SysResourceMapper extends CommonMapper<SysResource> {

    @Select("select T2.id,T2.sys_info_id sysInfoId,T2.parent_id parentId,T2.type,T2.code,T2.name,"
            + "T2.url,T2.location,T1.resource_columns columns\n"
            + "from sys_role_resource  T1 LEFT JOIN sys_resource T2 on T1.sys_resource_id = T2.id  \n"
            + "where T1.sys_info_id = #{sysInfoId} and T1.sys_role_id = #{sysRoleId} ")
    List<SysResource> getUserRoleSysResource(@Param("sysRoleId") Long sysRoleId, @Param("sysInfoId") Long sysInfoId);

    @Select("select T2.id,T2.sys_info_id sysInfoId,T2.parent_id parentId,T2.type,T2.code,T2.name,"
            + "T2.url,T2.location,T1.resource_columns columns\n"
            + "from sys_role_resource  T1 LEFT JOIN sys_resource T2 on T1.sys_resource_id = T2.id  \n"
            + "where T1.sys_info_id = #{sysInfoId} and T1.sys_role_id = #{sysRoleId} and T1.pid= #{pid} ")
    List<SysResource> getUserRoleSysResourceByPid(@Param("sysRoleId") Long sysRoleId, @Param("sysInfoId") Long sysInfoId,
                                                  @Param("pid") Long pid);

    @Select("select T2.id,T2.sys_info_id sysInfoId,T2.parent_id parentId,T2.type,T2.code,T2.name,"
            + "T2.url,T2.location,T1.resource_columns columns\n"
            + "from sys_role_resource  T1 LEFT JOIN sys_resource T2 on T1.sys_resource_id = T2.id  \n"
            + "where T1.sys_info_id = #{sysInfoId} and T1.sys_role_id = #{sysRoleId} and T2.url=#{url} ")
    List<SysResource> getSysUserPermissionByUrl(@Param("sysRoleId") Long sysRoleId, @Param("sysInfoId") Long sysInfoId,
                                                @Param("url") String url);
}
